<template>
	<uni-nav-bar title="盘库" left-icon="left" @clickLeft="navBack" :fixed="true" statusBar></uni-nav-bar>
	<!-- 切换 -->
	<view class="package" style="padding:0px;">
		<z-tabs ref="tabs" :list="list" :current="current" @change="tabsChange" inactive-color="#333" />
	</view>
	<scroll-view scroll-y="true" enable-back-to-top @scrolltolower="loadMore" class="package_sale scroll-box"
		:style="{ height: pageHeight + 'px' }">
		<view class="space-between" v-for="item in orderLists" :key="item.id">
			<view style="width:60%">
				{{item.fill_name?item.fill_name:item.service_name}}（{{item.fill_id?item.fill_id:item.service_id}}）
			</view>
			<view style="margin-top:10rpx;font-size: 26rpx;">{{item.createtime}}</view>
		</view>
		<Popu v-if="orderLists.length<1" :pageHeight="pageHeight" text="暂无盘库记录"></Popu>
	</scroll-view>
	<!-- @click="navTo('Sale/inventory/typeList')" -->
	<view class="add" @click="jump()">新增</view>
</template>

<script setup lang="ts">
	import { navBack, navTo } from '@/utils/navigator';
	import Popu from '@c/earthPushing/common/popu.vue';
	import { ref } from 'vue';
	import { toPublish } from '@mqtt';
	import { showLoading } from '@/utils/prompt';
	import { onShow } from '@dcloudio/uni-app';
	import { getAmountPanList } from '@/gql/earthPushing/warehouse';
	import { getDriverID } from '@/stores/driverID';
	const staff_id = getDriverID();
	const list = [{ name: '加注机' }, { name: '服务点' }]
	const current = ref(0)
	const tabs = ref(null)
	const type = ref('fill')
	const orderLists = ref([]);
	const lastPage = ref(1);
	const currentPage = ref(1);
	const pageHeight = ref();
	uni.getSystemInfo({
		success: function (res) {
			pageHeight.value = res.windowHeight - 175;
		},
	});
	onShow(() => {
		current.value = 0
		currentPage.value = 1
		orderLists.value = []
		type.value = 'fill'
		init()
	})
	function init() {
		showLoading()
		const payload = {
			query: getAmountPanList,
			variables: {
				page: currentPage.value,
				staff_id,
				type: type.value
			},
		};
		toPublish(
			'ql/staff/getAmountPanList',
			payload,
			(obj : any) => {
				const { getAmountPanList } = obj.data;
				orderLists.value = [...orderLists.value, ...getAmountPanList.list];
				lastPage.value = getAmountPanList.lastpage;
			}
		);
	}
	/**
	 * 加载更多
	 */
	function loadMore() {
		if (currentPage.value < lastPage.value) {
			currentPage.value++;
			init();
		}
	}
	//tabs通知swiper切换
	function tabsChange(index : number) {
		current.value = index;
		type.value = index === 0 ? 'fill' : 'service'
		currentPage.value = 1;
		orderLists.value = [];
		init();
	}
	function jump(){
		if(current.value===0){
			navTo('Sale/inventory/addInventory')
		}else{
			navTo('Sale/inventory/addInventory?state=1')
		}
	}
</script>

<style scoped lang="less">
	.space-between {
		border-bottom: 1px solid #eee;
		padding: 20rpx 0px;
		box-sizing: border-box;
	}

	.space-between:nth-of-type(1) {
		padding-top: 0px;
	}

	.add {
		width: 480rpx;
		height: 100rpx;
		background: linear-gradient(-10deg, #2C96F9, #1B91FF);
		border-radius: 5px;
		text-align: center;
		line-height: 100rpx;
		color: #fff;
		margin: 20rpx auto;
		font-size: 32rpx;
	}
</style>